#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pi;
const int N = 1010, M = 3010, INF = 0x3f3f3f3f;
int h[N], e[M], ne[M], w[M], idx;
int dist[N], cow[N], n, m, p;
bool st[N];
void add(int a, int b, int c) {
  e[idx] = b, w[idx] = c, ne[idx] = h[a], h[a] = idx++;
}
int dij(int s) {
  memset(st, 0, sizeof st);
  memset(dist, 0x3f, sizeof dist);
  dist[s] = 0;
  priority_queue<pi, vector<pi>, greater<>> heap;
  heap.push({0, s});
  while (heap.size()) {
    auto [d, u] = heap.top();
    heap.pop();
    if (st[u]) continue;
    st[u] = true;
    for (int i = h[u]; ~i; i = ne[i]) {
      int j = e[i];
      if (dist[j] > d + w[i]) {
        dist[j] = d + w[i];
        heap.push({dist[j], j});
      }
    }
  }
  int ans = 0;
  for (int i = 1; i <= n; ++i) {
    int j = cow[i];
    if (dist[j] == INF) return INF;
    ans += dist[j];
  }
  return ans;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  memset(h, -1, sizeof h);
  cin >> n >> p >> m;
  for (int i = 1; i <= n; ++i) cin >> cow[i];
  while (m--) {
    int a, b, c;
    cin >> a >> b >> c;
    add(a, b, c), add(b, a, c);
  }
  int ans = INF;
  for (int i = 1; i <= p; ++i) ans = min(ans, dij(i));
  cout << ans << endl;
  return 0;
}
